<?
	include('chksession.php');
	include('conn.php');
	session_start();
    //$data = file_get_contents("php://input");
    //$objData = json_decode($data);
	
	   $msg='';
	   $opbaltranid = $_REQUEST['opbaltranid'];
	   $opbaldate = $_REQUEST['opbaldate'];
	   $custid = $_REQUEST['custid'];
	   $trancat = $_REQUEST['trancat'];
	   $amtpaid = $_REQUEST['amtpaid'];
	   $amtreceived = $_REQUEST['amtreceived'];
	   $comment = $_REQUEST['comment'];
	   $enteredby = $_SESSION['username'];
	   
		echo $opbaltranid.",".$opbaldate.",".$custid.",".$trancat.",".$amtpaid.",".$comment.",".$enteredby;
	  
		//exit;
		
		
		$sqlc="select count(*) cnt from opbalmast where status = 0 and opbaltranid='".$opbaltranid."'";
		$resc=mysql_query($sqlc);
		$rowc=mysql_fetch_assoc($resc);
		
		
			if($rowc['cnt']==0)
			{
				$sql="insert into opbalmast(opbaldate,custid,trancat,amtpaid,amtreceived,comment,enteredby,entrydt)
				values('".$opbaldate."','".$custid."','".$trancat."','".$amtpaid."','".$amtreceived."','".$comment."','".$enteredby."',sysdate())";
												
				$res=mysql_query($sql);
				if($res)
					$msg='Record saved successfully';			
			}
			else
			{
			//	$sql="update expensemast set expdate='$expdate',empid='$empid',expensecat='$expensecat',amtpaid='$amtpaid',comment='$comment',enteredby='$enteredby',entrydt=sysdate() where exptranid='$exptranid'";
				
				//echo $sql; exit;
				
				$res=mysql_query($sql);
				if($res)
					$msg='Record updated successfully...';					
			}
		
				
	    echo $msg;
?>